//
//  DengLu.m
//  10-10
//
//  Created by 钟纪旺 on 16/10/18.
//  Copyright © 2016年 zjw. All rights reserved.
//

#import "DengLu.h"

#import "Network.h"
@interface DengLu ()@property (strong, nonatomic) IBOutlet UITextField *userName;
@property (strong, nonatomic) IBOutlet UITextField *password;


@end

@implementation DengLu

- (void)showMessage:(NSString *)message
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示消息" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    
    [alertVC addAction:ok];
    
    [self presentViewController:alertVC animated:YES completion:nil];
}


- (IBAction)onClick:(id)sender
{
    
    
    if (!_userName.text.length) {
        [self showMessage:@"请输入用户名"];
        return;
    }
    
    if (!_password.text.length) {
        [self showMessage:@"请输入密码"];
        return;
    }

    
    [Network loginWithName:self.userName.text password:self.password.text completeCallBack:^(NSDictionary *dic) {
       
        
        if ([dic[@"errcode"] intValue] == 0) {
            UITabBarController *con = [self.storyboard instantiateViewControllerWithIdentifier:@"liudehua"];
            //推进去
            [self presentViewController:con animated:YES completion:^{
                
            }];
        }else {
            [self showMessage:dic[@"errmsg"]];
        }
        
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.password.secureTextEntry = YES;
    self.password.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.userName.clearButtonMode = UITextFieldViewModeWhileEditing;
    UIToolbar *tobView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
    [tobView setBarStyle:UIBarStyleBlack];
    UIBarButtonItem *button1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *button2 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
    UIBarButtonItem* doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成"style:UIBarButtonItemStyleDone target:self action:@selector(endEdit)];
    NSArray* buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
    [tobView setItems:buttonsArray];
    [self.userName setInputAccessoryView:tobView];
    [self.password setInputAccessoryView:tobView];
    
}
-(void) endEdit
{
    [self.view endEditing:YES];
}

- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    [self.view endEditing:YES];
}

////下导航消失
//-(void)viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//    self.navigationController.tabBarController.tabBar.hidden = YES;
//}
//
////下导航出现
//- (void)viewWillDisappear:(BOOL)animated {
//
//    [super viewWillDisappear:animated];
//    [super viewWillAppear:animated];
////    self.navigationController.tabBarController.tabBar.hidden = NO;
//}
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}
//

@end
